package top.buaarobot.webserver.web.rest;

import com.alibaba.fastjson.JSONObject;
import top.buaarobot.webserver.domain.SystemNotice;
import top.buaarobot.webserver.service.SystemNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/api/systemNotice")
public class SystemNoticeResource {
    @Autowired
    private SystemNoticeService systemNoticeService;

    @PostMapping("/get")
    public Iterable<SystemNotice> GetSystemNotice(@RequestBody JSONObject json) {
        int userId = json.getIntValue("userId");
        System.out.println("[POST /api/systemNotice/get]: 用户id:"+userId);
        return systemNoticeService.Get(userId);
    }

    @PostMapping("/add")
    public String AddSystemNotice(@RequestBody JSONObject json) {
        SystemNotice systemNotice = (SystemNotice) JSONObject.toJavaObject(json, SystemNotice.class);
        System.out.println("[POST /api/systemNotice/add]: "+json.getString("content"));
        return this.systemNoticeService.Add(systemNotice);
    }

    @PostMapping("/delete")
    public String DeleteSystemNotice(@RequestBody JSONObject json) {
        int id = json.getIntValue("id");
        System.out.println("[POST /api/comment/delete]: 通知id:"+id);
        return this.systemNoticeService.Delete(id);
    }

    @PostMapping("/clear")
    public String ClearSystemNotice(@RequestBody JSONObject json) {
        int userId = json.getIntValue("userId");
        System.out.println("[POST /api/comment/clear]: 用户id:"+userId);
        return this.systemNoticeService.Clear(userId);
    }

    @PostMapping("/read")
    public String SystemNoticeRead(@RequestBody JSONObject json) {
        int id = json.getIntValue("id");
        System.out.println("[POST /api/comment/read]: 通知id:"+id);
        return this.systemNoticeService.Read(id);
    }
}